#pragma once
#include <dokan/dokan.h>
#include <dokan/fileinfo.h>
#include <Windows.h>

#include "BackupFSFileNodes.h"
#include "BackupFilesystem.h"
#include "BackupFSCore.h"
#include <iostream>
/*
API for the user
Use the class to mount or umount the file system
*/
namespace BackupFS
{
	class BackupVFS
	{
	public:
		BackupVFS() = default;
		bool Mount(const std::wstring& data_path, const std::wstring mount_point, LONGLONG fs_size = 0);
		void Wait();
		void Umount();
		void SetFlushFrequency(int frequency);
		void SetCacheNumber(ULONGLONG num);
		std::wstring GetMountPoint();
		void SetMountPoint(const std::wstring& mount_point);
		LONGLONG GetFSSize();
		LONGLONG GetFreeSize();
		void SetFsSize(LONGLONG size);
		void SetReadOnly(bool read_only);
		void SetMode(FILE_SYSTEM_MODE mode);
		bool IsMounted() { return _Mounted; }
		void SetBitmapGroupSize(LONGLONG size) { BACKUPFS_BITMAP_GROUP_SIZE = size; }
		/*
		Create a new file
		*/
		bool CreateFile(const std::wstring& file_name,LONGLONG file_size,DWORD attributes);
		bool ReadFile(const std::wstring& file_name, LPVOID buffer, DWORD bufferlength, LPDWORD readlength, LONGLONG offset);
		bool WriteFile(const std::wstring& file_name, LPCVOID buffer,DWORD number_of_bytes_to_write,LPDWORD number_of_bytes_written,LONGLONG offset);
		void CloseFile(const std::wstring& file_name);
	public:
		std::unique_ptr<BackupFSFileNodes> FsFileNodes;
	
	private:
		DOKAN_HANDLE _Instance = nullptr;
		std::wstring _MountPoint;
		std::wstring _DataPath;
		std::atomic<int>_FlushFrequency = 3;
		bool _ReadOnly = false;
		bool _Mounted = false;
		FILE_SYSTEM_MODE _Mode = FILE_SYSTEM_MODE::NORMAL_MODE;
	};
} 

